package com.example.idachuappone.person.method;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.example.idachuappone.promptly.entity.UserInfo;
import com.example.idachuappone.utils.Constant;
import com.example.idachuappone.utils.NetUtil;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

public class UserInfoMethod {

	public static interface CallBack {
		void onFail();

		void onSuccess(UserInfo userInfo);
	}

	public static interface CallBackString {
		void onFail();

		void onSuccess(String str);
	}

	static class AnonymousClass_1 extends RequestCallBack<String> {
		private final/* synthetic */CallBack val$callBack;

		AnonymousClass_1(CallBack callBack) {
			this.val$callBack = callBack;
		}

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {
			try {
				JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
				if (jsonObject.getInt("code") == 10000) {
					UserInfo userInfo = new UserInfo();
					userInfo.parseJson(jsonObject.getJSONObject("data"));
					this.val$callBack.onSuccess(userInfo);
					return;
				}
				this.val$callBack.onFail();
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		@Override
		public void onFailure(HttpException arg0, String arg1) {
			this.val$callBack.onFail();
		}
	}

	static class AnonymousClass_2 extends RequestCallBack<String> {
		private final/* synthetic */CallBackString val$callBackString;

		AnonymousClass_2(CallBackString callBackString) {
			this.val$callBackString = callBackString;
		}

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {
			this.val$callBackString.onSuccess(NetUtil.unescapeUnicode(responseInfo.result));
		}

		@Override
		public void onFailure(HttpException arg0, String arg1) {
			this.val$callBackString.onFail();
		}
	}

	static class AnonymousClass_3 extends RequestCallBack<String> {
		private final/* synthetic */CallBackString val$callBackString;

		AnonymousClass_3(CallBackString callBackString) {
			this.val$callBackString = callBackString;
		}

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {
			this.val$callBackString.onSuccess(NetUtil.unescapeUnicode(responseInfo.result));
		}

		@Override
		public void onFailure(HttpException arg0, String arg1) {
			this.val$callBackString.onFail();
		}
	}

	public static void getUserInfo(Context context, CallBack callBack) {
		NetUtil.get(context, Constant.USER_INFO, 100, new AnonymousClass_1(callBack));
	}

	public static void getUserYuE(Context context, CallBackString callBackString) {
		NetUtil.get(context, Constant.USER_INFO_YU_E, 100, new AnonymousClass_2(callBackString));
	}

	public static void getUserYuEDetail(Context context, CallBackString callBackString) {
		NetUtil.get(context, Constant.USER_INFO_YU_E_DETAIL, 100, new AnonymousClass_3(callBackString));
	}
}
